package com.itheima.controller.systemInfo;

import cn.hutool.core.util.ObjUtil;
import com.itheima.domin.vo.Result;
import com.itheima.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**文件上传
 * @Author:上官徵羽
 * @Date: 2025/07/12 17:11
 * @Description TODO 今日内容:
 */
@RestController
@Slf4j
public class FileController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    @PostMapping(value = "/upload")
    public Result upload (MultipartFile file) throws Exception {
        log.info("{}",file);
        if (ObjUtil.isNull(file)||file.getSize()==0){
            return Result.error("上传文件不能为空");
        }
        String path = aliyunOSSOperator.upload(file.getBytes(),file.getOriginalFilename());
        return Result.success(path);
    }

}
